import java.util.Random;

public class demo01 {
    public static int sum1=0;
    public static int sum2 = 0;
    public static void main(String[] args) throws InterruptedException {
        long time1= System.currentTimeMillis();
        int[] arr=new int[10000000];
        Random r=new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i]=r.nextInt(100)+1;
        }

        Thread t1=new Thread(()->{

            for (int i = 0; i < arr.length; i+=2) {
                sum1+=arr[i];
            }
            System.out.println("偶数和为"+sum1);
        });

        Thread t2=new Thread(()-> {
            for (int i = 1; i < arr.length; i += 2) {
                sum2 += arr[i];
            }
            System.out.println("奇数和为" + sum2);
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        int sum=sum1+sum2;
        System.out.println("数组和为："+sum);

        long time2= System.currentTimeMillis();
        System.out.println("执行时间为："+(time2-time1));
    }
}
